package org.example.controller;


import org.example.dto.RolePageDTO;
import org.example.result.PageResult;
import org.example.result.Result;
import org.example.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("role")
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;

    /**
     * 角色管理
     *
     * @return
     */
    @RequestMapping("roleList")
    public Result roleList(RolePageDTO rolePageDTO) {
        PageResult pageResult = roleService.listAll(rolePageDTO);
        return Result.success(pageResult);
    }


    /**
     * 修改
     */
    @RequestMapping("updateRole")
    public Result updateRole(RolePageDTO rolePageDTO) {
        boolean role = roleService.updateRole(rolePageDTO);
        return Result.success(role);
    }

    /**
     * 新增角色
     */
    @RequestMapping("addRole")
    public Result addRole(RolePageDTO rolePageDTO) {
        boolean b = roleService.add(rolePageDTO);
        return Result.success(b);
    }


    /**
     * 删除角色
     */
    @RequestMapping("deleteRole")
    public Result deleteRole(Integer id) {
        boolean b = roleService.delete(id);
        return Result.success(b);
    }

}
